cmake_minimum_required(VERSION 3.18)
project(image_grayscale CXX CUDA)

set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CXX_STANDARD 17)

find_package(CUDAToolkit REQUIRED)

function(set_target_options target)
    target_include_directories(${target} PRIVATE
            src/lodepng/
            src/
    )

    target_link_libraries(${target}
            CUDA::cudart
    )

    if (CMAKE_BUILD_TYPE STREQUAL "Debug")
        target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-G>)
    else ()
        # needed to get SASS correlation in NCU
        target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-lineinfo>)
    endif ()


    set_target_properties(${target} PROPERTIES
            CUDA_SEPARABLE_COMPILATION ON)
endfunction()

# use this for profiling in nsight compute
add_executable(memory_workload_mode
        src/main.cu
        src/lodepng/lodepng.cpp
)
set_target_options(memory_workload_mode)

# use this for simply running the kernels in a benchmark mode
add_executable(memory_workload_benchmark
        src/main.cu
        src/lodepng/lodepng.cpp
)
set_target_options(memory_workload_benchmark)
target_compile_definitions(memory_workload_benchmark PRIVATE BENCHMARK=1)